﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Owin;

[assembly: OwinStartup(typeof(MessageHubs.Startup))]
namespace MessageHubs
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // 有关如何配置应用程序的详细信息，请访问 http://go.microsoft.com/fwlink/?LinkID=316888

            #region PersistentConnection
            ConnectionConfiguration connectionConfig = new ConnectionConfiguration()
                {
                    EnableJSONP = true//支持跨域
                };
            //建立连接超时
            //GlobalHost.Configuration.TransportConnectTimeout = TimeSpan.FromSeconds(5);//消息传递超时时间间隔
            //GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);//连接超时 当KeepAlive禁用时有效
            //GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);//断开连接超时
            //GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);//客户端通知服务器处于活动状态的时间间隔 设置空可禁用
            //GlobalHost.Configuration.DefaultMessageBufferSize = 1000;//默认消息缓冲区大小
            //GlobalHost.Configuration.LongPollDelay = TimeSpan.FromSeconds(0);//长轮询最小时间间隔

            //PersistentConnection
            app.MapSignalR<IoTPersistentConnection>("/IoT", connectionConfig);
            #endregion

            #region Hubs
            //Hubs
            HubConfiguration hubConfig = new HubConfiguration()
            {
                EnableJSONP = true,//支持跨域
                EnableDetailedErrors = true//支持异常捕获
            };
            //Hubs 默认映射到signalr -----<script src="signalr/js"></script>
            app.Map("/chat", map =>//<script src="/chat/js"></script>
            {
                map.UseCors(CorsOptions.AllowAll);
                map.RunSignalR(hubConfig);
            });
            //app.MapSignalR();
            #endregion
        }
    }
}
